/**
 * 签到页面
 * author:yinht
 * date:2017年6月1日9:10:42
 */
;
define(function(require, exports, module) {
	var wechat = require("wechat");

	var men_details = {
		/**
		 * bindEvent 页面事件
		 */
		bindEvent: function() {
			//返回
			$("#return_mendetails").unbind().on("click", function() {
	//			window.localStorage.setItem("type","");
				window.localStorage.setItem("pk_member","");
				window.history.back(-1);
			});
//			$(".pro_po_list>li").unbind().on("click", function() {
//				$(this).css("background-color","#4381e1");
//			});
			//被驳回
//			$("#bohui").unbind().on("click", function() {
//				var picker = new mui.PopPicker();
//				picker.setData([{ value: '1', text: '金额与等级不匹配1' }, { value: '2', text: '金额与等级不匹配2' }, { value: '3', text: '金额与等级不匹配2' }, { value: '4', text: '其他原因' }]);
//
//				picker.show(function(selectItems) {
//					$("#bohui").val(selectItems[0].text);
//					picker.dispose();
//				}, function(selectItems) {
//					picker.dispose();
//				});
//			});
			//编辑
			$("#bianji").unbind().on("click", function() {
				window.localStorage.setItem("update","编辑");
				window.sessionStorage.setItem("bianji","1");
				window.location.href = "#/index/newmenber";
			});
			//审核通过
			$("#pendingpass").unbind().on("click", function() {
				
				//跳转到审批中心
				window.location.href = "#/index/pending";
			});
		},
		/**
		 * 进行页面路由监听配置
		 * 
		 */
		bindRout: function() {
//			//公共页面监听路由
//			Path.map("#home").to(function() {
//				//返回首页
//				common.loadPage({
//					pageUrl: "html/index.html",
//					reload: true,
//					from: "left"
//				});
//			});
			Path.map("#/index/:page_name").to(function() {
				console.log(this.params["page_name"]);
				var page_name = this.params["page_name"];
				var from = "right"; //从右边过来
				if((page_name == "pending")||(page_name == "ManagementSup")||(page_name == "memberShip")||(page_name == "Management")||(page_name == "followalert")||(page_name == "birthdayremind")){
					from = "left";
				}else{
					from = "right";
				}
				//记录状态
				common.loadPage({
					pageUrl: "html/" + page_name + ".html",
					reload: true,
					from: from
				});
			});
			Path.listen();
		},

		/**
		 * 页面数据加载
		 */
		loadData: function() {
			//接口数据
			var supertype = window.localStorage.getItem("supertype");
			var type = window.localStorage.getItem("type");
			var permissions = window.localStorage.getItem("permissions");
			if(permissions == "0"){
				$(".tobox").text("上级：");
					if(supertype == "2"){
					//基本信息页面
					$("#bianji").css("display","none");
					$(".pro_footer").css("display","none");
					$(".sp_top").css("display","none");
					$(".sp_top_reject").css("display","none");
				}else if(supertype == "0"){
					//待审批
					$("#bianji").css("display","none");
					$(".pro_footer").css("display","none");
					$(".sp_top_reject").css("display","none");
					
				}else if(supertype == "1"){
					//被驳回
					$(".sp_top").css("display","none");
					$(".pro_footer").css("display","none");
				}
			}else if(permissions == "1"){
				if(type == "2"){
					$("#bianji").css("display","none");
					$(".sp_top_reject").css("display","none");
				}else if(type == "3"){
					$("#bianji").css("display","none");
					$(".pro_footer").css("display","none");
					$(".sp_top_reject").css("display","none");
				}
				//加载数据
				
			}
			
			 
			//初始化信息
			var initializestr = window.localStorage.getItem("initialize");
			var supertype = window.localStorage.getItem("supertype");
			var pk_user = window.localStorage.getItem("pk_user");
			var pk_member = window.localStorage.getItem("pk_member");
			var initializeObj = JSON.parse(initializestr);
			var docker = initializeObj.userInfo.psnName;
			var dockertel = initializeObj.userInfo.phone;
			$(".docker").text(docker);
			$(".dockertel").text(dockertel);
			var listtype = window.localStorage.getItem("listtype");
			
			var param = {
					pk_user: pk_user,
					pk_member:pk_member,
					supertype:supertype,  //判断是待审批还是被驳回还是会员
					listtype:listtype     //判断是新增还是变更
		           }
			common.loadData({
				url: "/service/RRTPubServlet?method=getMemberDetail", //"/UMPPubServlet?method=getWxUserInfo",
				param: param,
				successCallBack: men_details.getMemberDetailCallBack, //回调函数
				dataSource: "getMemList",
				cache: false
			});
				var iscroll = require("iscroll"); 
				common.initIscroll({
					container: "iscrollContent_men_details",
					isVertical:true ,
					showScrollBar: true
				});
		},
		getMemberDetailCallBack: function(json){
			console.log(JSON.stringify(json));
			window.localStorage.setItem("userInfo",JSON.stringify(json));
			if(json.status == "0") {
				$(".khname").text(json.data.name);
				$(".sex").text(json.data.sex);
				$(".khbirth").text(json.data.birthday);
				$(".khtel").text(json.data.tel);
				if(json.data.address.receiverProvince==json.data.address.receiverCity){
					$(".khaddress").text(json.data.address.receiverProvince+json.data.address.receiverRegion);
				}else{
					$(".khaddress").text(json.data.address.receiverProvince+json.data.address.receiverCity+json.data.address.receiverRegion);	
				}
				$(".addressdetails").text(json.data.address.receiverAddr);
				$(".national").text(json.data.national);
				$(".Ancestral").text(json.data.Ancestral);
				$(".hobby").text(json.data.hobbies);
				$(".entityname").text(json.data.entityname);
				$(".Subordinate").text(json.data.subordinate);
				$(".position").text(json.data.position);
				var label = json.data.memolabel;
				if(label && label.length>0){
					var html = "";
					for(var i=0;i<label.length;i++){
						html += '<span class="lablespan">'+label[i]+'</span>';
					}
					$(".label").append(html);
				}
				
				$(".consumption").text(json.data.consumption);
				$(".level").text(json.data.level);
				$(".Consumptionlevel").text(json.data.consumptionlevel);
				$(".mygoodsitems").text(json.data.myseries);
				$(".mygood").text(json.data.mygood);
				$(".competinggood").text(json.data.competinggood);
				$(".competinggooditems").text(json.data.competinggooditems);
				$(".pendingname").text(json.data.superior);
				$(".shangji").text(json.data.superior);
				$(".reason").text(json.data.reason);
				if(window.localStorage.getItem("ishide")=="true"){
					$(".sp_top_reject").hide();
					$(".sp_top").hide();
					$(".bianji").hide();
					window.localStorage.removeItem("ishide");
				}
			} else {
				common.showTip({
					content: json.message
				});
			}
		},
		/**
		 * each page init mothed
		 */
		initialize: function() {

			this.loadData();
			//事件绑定
			this.bindEvent();
			//路由绑定
			this.bindRout();
		}
	};

	module.exports = men_details;
});	

